package com.collectplus.express.app;

import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.view.View;
import android.view.ViewGroup;
import droid.frame.app.Callback;

/**
 * app用到的动画view
 * 
 * @author coffee<br>
 *         2016-11-24上午10:10:33
 */
public class Animator {

	/**
	 * 沿着Y轴缩放
	 * 
	 * @param targetView
	 *            执行动画的目标view
	 * @param values
	 *            单位像素 <br>
	 *            y轴变化值,例如 传入(view, 0, 100) 则view懂0慢慢变大到100
	 */
	public static void scaleY(final View targetView, final Callback callback, final int... values) {
		ValueAnimator scaleY = ValueAnimator.ofInt(values);
		scaleY.addUpdateListener(new AnimatorUpdateListener() {
			@Override
			public void onAnimationUpdate(ValueAnimator animation) {
				int animatorValue = Integer.valueOf(animation.getAnimatedValue() + "");
				ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) targetView.getLayoutParams();
				params.height = animatorValue;
				targetView.setLayoutParams(params);
				if (values[values.length - 1] == 0 && animatorValue == 0) {
					targetView.setVisibility(View.GONE);
				}
				if (callback != null) {
					callback.execute();
				}
			}
		});
		scaleY.setTarget(targetView);
		scaleY.setDuration(250);
		scaleY.start();
	}

}
